﻿using System.Text;
using Rodunu.Utilities.Email.Properties;

namespace Rodunu.Utilities.Email
{
    public class PostOffice
    {
        private readonly Mailer _mailer;

        public PostOffice()
        {
            _mailer = new Mailer();
        }

        public void SendAccountValidation(string toAddress, string subject, string link)
        {
            StringBuilder message = new StringBuilder(Resources.AccountValidationLetter);
            message.Replace("{VerificationLink}", link);
            string subjectLine = subject;

            if (string.IsNullOrEmpty(subjectLine))
            {
                subjectLine = Settings.Default.DefaultSubjectLine;
            }
            _mailer.SendEmail(toAddress, subjectLine, message.ToString());
        }

        public void SendNewUserWelcomeLetter(string toAddress, string subject, string firstName)
        {
            StringBuilder message = new StringBuilder(Resources.NewUserWelcomeLetter);
            message.Replace("{FirstName}", firstName);
            string subjectLine = subject;

            if (string.IsNullOrEmpty(subjectLine))
            {
                subjectLine = Settings.Default.DefaultSubjectLine;
            }
            _mailer.SendEmail(toAddress, subjectLine, message.ToString());
        }

        public void SendFriendRequest(string toAddress, string userName, string currentUser)
        {
            var message = new StringBuilder(Resources.NewFriendRequest);
            message.Replace("{UserName}", userName);
            message.Replace("{UserLink}", "http://rmovies/rodunumovies/Friends/FriendsRequest.ashx?UserName=" + userName);

            _mailer.SendEmail(toAddress, "Friend Request", message.ToString());
        }

        public void ConfirmFriendRequest(string toAddress, string userName, string currentUser)
        {
            var message = new StringBuilder(Resources.AccptedFriendRequest);
            message.Replace("{UserName}", userName);
            message.Replace("{UserLink}", "http://rmovies/rodunumovies/User/UserInfo.ashx?userName=" + userName);

            _mailer.SendEmail(toAddress, "Friend Request Accepted", message.ToString());
        }

        public void MovieBorrowRequest(string toAddress, string userName, string movieName)
        {
            var message = new StringBuilder(Resources.MovieBorrowRequest);
            message.Replace("{UserName}", userName);
            message.Replace("{MovieName}", movieName);
            //message.Replace("{UserLink}", "http://rmovies/rodunumovies/User/UserInfo.ashx?userName=" + userName);

            _mailer.SendEmail(toAddress, "Movie Request", message.ToString());
        }

        public void MovieRequestAccepted(string toAddress, string userName, string movieName, string userMessage)
        {
            var message = new StringBuilder(Resources.MovieRequestAccepted);
            message.Replace("{UserName}", userName);
            message.Replace("{MovieName}", movieName);
            message.Replace("{Message}", userMessage);

            _mailer.SendEmail(toAddress, "Movie Request Accepted", message.ToString());
        }

        public void MovieRequestDenied(string toAddress, string userName, string movieName, string userMessage)
        {
            var message = new StringBuilder(Resources.MovieRequestDenied);
            message.Replace("{UserName}", userName);
            message.Replace("{MovieName}", movieName);
            message.Replace("{Message}", userMessage);

            _mailer.SendEmail(toAddress, "Movie Request Denied", message.ToString());
        }
    }
}
